// 导入 node 自带模块 url
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],

  resolve: {
    // 路径别名配置
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },

  server: {
    /**
     * 代理跨域的配置
     */
    proxy: {
      /**
       * http://localhost:5173/api/admin/base/open/captcha =>
       * http://127.0.0.1:8001/admin/base/open/captcha
       */
      "/api": {
        target: "http://127.0.0.1:8001", // 目标地址
        changeOrigin: true, // 用于修改目标地址目标接受的请求头中的host字段的值
        rewrite: (path) => path.replace("/api", ""), // 路径重写
      },

      "/test": {
        target: "http://localhost:3000",
        // changeOrigin: true,
        rewrite: (path) => path.replace("/test", ""),
      },
    },
  },
});
